package com.ruoyi.web.controller.qsng;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.qsng.domain.KClearinghouse;
import com.ruoyi.qsng.service.IKClearinghouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 交流中心Controller
 *
 * @author kanglou
 * @date 2023-06-07
 */
@RestController
@RequestMapping("/qsng/clearinghouse")
@Api(tags = "pc--交流中心Controller")
public class KClearinghouseController extends BaseController {
    @Autowired
    private IKClearinghouseService kClearinghouseService;

    /**
     * 查询交流中心列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:clearinghouse:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询交流中心列表")
    public TableDataInfo list(KClearinghouse kClearinghouse) {
        startPage();
        List<KClearinghouse> list = kClearinghouseService.selectKClearinghouseList(kClearinghouse);
        return getDataTable(list);
    }

    /**
     * 导出交流中心列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:clearinghouse:export')")
    @Log(title = "交流中心", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出交流中心列表")
    public void export(HttpServletResponse response, KClearinghouse kClearinghouse) {
        List<KClearinghouse> list = kClearinghouseService.selectKClearinghouseList(kClearinghouse);
        ExcelUtil<KClearinghouse> util = new ExcelUtil<KClearinghouse>(KClearinghouse.class);
        util.exportExcel(response, list, "交流中心数据");
    }

    /**
     * 获取交流中心详细信息
     */
    @PreAuthorize("@ss.hasPermi('qsng:clearinghouse:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取交流中心详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(kClearinghouseService.selectKClearinghouseById(id));
    }

    /**
     * 新增交流中心
     */
    @PreAuthorize("@ss.hasPermi('qsng:clearinghouse:add')")
    @Log(title = "交流中心", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增交流中心")
    public AjaxResult add(@RequestBody KClearinghouse kClearinghouse) {
        return toAjax(kClearinghouseService.insertKClearinghouse(kClearinghouse));
    }

    /**
     * 修改交流中心
     */
    @PreAuthorize("@ss.hasPermi('qsng:clearinghouse:edit')")
    @Log(title = "交流中心", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改交流中心")
    public AjaxResult edit(@RequestBody KClearinghouse kClearinghouse) {
        return toAjax(kClearinghouseService.updateKClearinghouse(kClearinghouse));
    }

    /**
     * 删除交流中心
     */
    @PreAuthorize("@ss.hasPermi('qsng:clearinghouse:remove')")
    @Log(title = "交流中心", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除交流中心")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(kClearinghouseService.deleteKClearinghouseByIds(ids));
    }
}
